**************************
***	RUN USING STATA 16 ***
**************************

* Purpose: graph WASSCE results against study findings.
* Last updated: 20 Apr 2023

*---------------------------------------------------------------------------
* Graph WASSCE results against study findings
*---------------------------------------------------------------------------

	use "$input\waec_pass.dta", replace
	
	*combining WAEC and study data	
	gen src = 1
	keep yr src mat_a_c_perc mat_d_e_perc
	tempfile waec
	save `waec'
	
	use "$output\mat_pass_estimates.dta", clear
	ren c_ mat_a_c_perc
	ren p_ mat_d_e_perc
	gen src = 2
	lab def src 1 "Population of WASSCE exam takers" 2 "Our sample of exam takers"
	lab values src src
	
	merge 1:1 yr src using `waec'
	drop _merge cal
	keep if yr>2010 // retain only study period
		
*** setup vars for graph

	gen mat_pass = mat_a_c_perc + mat_d_e_perc
	format %2.0f mat_a_c_perc mat_d_e_perc mat_pass

	tw ///
	(bar mat_a_c_perc yr if src==1, fc(black) fi(100) lc(none) barwidth(0.8)) ///
	(rbar mat_a_c_perc mat_pass yr if src==1, fc(white) fi(100) lcolor(black) lw(thin) barwidth(0.8)) ///
	, xlabel(2011(1)2019, nogrid angle(90) labsize(11pt)) ///
	ylabel(20 "20%" 40 "40%" 60 "60%" 80 "80%", nogrid labsize(11pt)) ysc(r(0 87)) ///
	xtitle("Year", size(11pt)) ytitle("") ///
	legend(order(2 1) lab(1 "Credit or better") lab(2 "Pass") pos(6) col(2) size(11pt)) ///
	subtitle("Panel A: All WASSCE Exam Takers", span pos(11) size(11pt)) ///
	xsize(2.25) ysize(3) name(a, replace)
	graph export "$graph\2a.png", replace
	graph export "$graph\2a.eps", replace	
	
	tw ///
	(bar mat_a_c_perc yr if src==2, fc(black) fi(100) lc(none) barwidth(0.8)) ///
	(rbar mat_a_c_perc mat_pass yr if src==2, fc(white) fi(100) lcolor(black) lw(thin) barwidth(0.8)) ///
	, xlabel(2011(1)2019, nogrid angle(90) labsize(11pt)) ///
	ylabel(20 "20%" 40 "40%" 60 "60%" 80 "80%", nogrid labsize(11pt)) ysc(r(0 87)) ///
	xtitle("Year", size(11pt)) ytitle("") ///
	legend(order(2 1) lab(1 "Credit or better") lab(2 "Pass") pos(6) col(2) size(11pt)) ///
	subtitle("Panel B: Our Sample of Exam Takers", span pos(11) size(11pt)) ///
	xsize(2.25) ysize(3) name(b, replace)
	graph export "$graph\2b.png", replace
	graph export "$graph\2b.eps", replace
	
	grc1leg a b, name(combo, replace)
	graph display combo, xsize(4.5) ysize(3.5)
	graph export "$graph\2.png", replace
	graph export "$graph\2.eps", replace	
*---------------------------------------------------------------------------
* Graph WASSCE results for other countries that participate
*---------------------------------------------------------------------------

	use "$input\wassce_ext.dta", replace
	
	tw ///
	(bar r_c year if country=="Nigeria", fc(black) fi(100) lc(none) barwidth(0.8)) ///
	(rbar  r_c r_c_p year if country=="Nigeria", fc(white) fi(100) lcolor(black) lw(thin) barwidth(0.8)) ///	
	, xlabel(2011(1)2019, nogrid angle(90) labsize(10pt)) ///
	ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", labsize(10pt)) ///
	legend(order(2 1) lab(2 "Pass") lab(1 "Credit or better") pos(6) col(2) size(10pt)) ///
	xtitle("Year", size(10pt)) subtitle("Panel A: Nigeria", span pos(11) size(10pt)) ///
	name(gph1, replace)
	
	tw ///
	(bar r_c year if country=="The Gambia", fc(black) fi(100) lc(none) barwidth(0.8)) ///
	(rbar  r_c r_c_p year if country=="The Gambia", fc(white) fi(100) lcolor(black) lw(thin) barwidth(0.8)) ///	
	, xlabel(2011(1)2019, nogrid angle(90) labsize(10pt)) ///
	ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", labsize(10pt)) ///
	legend(order(2 1) lab(2 "Pass") lab(1 "Credit or better") pos(6) col(2) size(10pt)) ///
	xtitle("Year", size(10pt)) subtitle("Panel B: The Gambia", span pos(11) size(10pt)) ///
	name(gph2, replace)	

	tw ///
	(bar r_c year if country=="Sierra Leone", fc(black) fi(100) lc(none) barwidth(0.8)) ///
	(rbar  r_c r_c_p year if country=="Sierra Leone", fc(white) fi(100) lcolor(black) lw(thin) barwidth(0.8)) ///	
	, xlabel(2011(1)2019, nogrid angle(90) labsize(10pt)) ///
	ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", labsize(10pt)) ///
	legend(order(2 1) lab(2 "Pass") lab(1 "Credit or better") pos(6) col(2) size(10pt)) ///
	xtitle("Year", size(10pt)) subtitle("Panel C: Sierra Leone", span pos(11) size(10pt)) ///
	name(gph3, replace)
	
	grc1leg gph1 gph2 gph3, col(3) ///
	name(combo, replace)
	
	graph display combo, xsize(4.5) ysize(3)
	graph export "$graph\4.png", replace
	graph export "$graph\4.eps", replace
	
	